﻿Imports System.IO
Public Class Frm_Ajout_Morfa9
    Dim nbr As Integer ' le nombre des fichiers ajouter récemment
    Private Sub Frm_Ajout_Morfa9_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
        Frm_Papier.Enabled = True
        
    End Sub

    Private Sub Frm_Ajout_Morfa9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txt_marji3ona.Text = Frm_Papier.dv.Num
        For Each pj As Jouinture In Partager.list_piece
            List_morfa9.Items.Add(New ListViewItem(New String() {pj.Nom}))
        Next
        'If Partager.hadf = "modi" Then
        '    Partager.close()
        '    Try
        '        List_morfa9.Items.Clear()
        '        For Each khib As Jouinture In Frm_Papier.avo.List_jouiture
        '            Partager.list_recherch.Add(khib)
        '            List_morfa9.Items.Add(New ListViewItem(New String() {khib.Nom}))
        '        Next
        '    Catch ex As Exception
        '        MsgBox(ex.Message)
        '    End Try
        'End If
    End Sub

    Private Sub Btn_Ajou_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Ajou.Click
        Dim i As Integer = 0
        Dim str As String
        If txt_chemain.Text <> "" Then
            Try
                For Each path As String In OpenFileDialog1.FileNames
                    str = OpenFileDialog1.SafeFileNames(i).Split(".")(0)

                    Dim Piece As New Jouinture(2, str, path.Split(".")(1))
                    Partager.list_piece.Add(Piece)
                    ReDim Preserve Partager.lstChemin(Partager.list_piece.Count - 1)
                    Partager.lstChemin(Partager.list_piece.Count - 1) = path

                    List_morfa9.Items.Add(New ListViewItem(New String() {Piece.Nom}))

                    i += 1
                Next
                nbr = i + 1
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            txt_chemain.Clear()

        End If
    End Sub

    Private Sub btn_parc_morfa9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_parc_morfa9.Click
        With OpenFileDialog1
            .FileName = ""
            .Title = "Ouvrir la Photo"
            .RestoreDirectory = True
            .InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            .FilterIndex = 1
        End With
        OpenFileDialog1.ShowDialog()
    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        txt_chemain.Text = OpenFileDialog1.FileNames.Count & " مرفقات"
    End Sub

    Private Sub btn_Supp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Supp.Click
        If List_morfa9.SelectedIndices.Count > 0 Then
            Partager.close()
            Try
                Partager.list_piece.RemoveAt(List_morfa9.SelectedIndices.Item(0))
                List_morfa9.SelectedItems(0).Remove()
                Frm_Papier.avo.suprimmer_jouitureDirect(Partager.list_piece(List_morfa9.SelectedIndices.Item(0)))
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر مرفق من القائمة", MsgBoxStyle.Information, "حذف")
        End If
    End Sub
End Class